﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using NTTDATA.BEENChina.ResultCertification.Config;
using NTTDATA.BEENChina.ResultCertification.PropertyGridUtil;
using NTTDATA.BEENChina.ResultCertification.PropertyGridUtil.CustomObject;

namespace NTTDATA.BEENChina.ResultCertification.Checker.Name
{   
    [Serializable]
    [VerfityAttribute(Id = "VerfityN0101", Name = "姓名结果为特定项目时抽出", CategoryType = EnumCategoryType.姓名, Model = true)]
    public class VerfityN0101 : VerfityOneResult
    {
        private CustomCollection<SpecialStringArray> _datalist = new CustomCollection<SpecialStringArray>() { Description = "指定数据列表" };
         

        [Category("指定数据列表"), Description("输入指定数据项目")]
        [TypeConverter(typeof(CustomCollectionConverter<SpecialStringArray>))]
        [RefreshProperties(RefreshProperties.All)]
        public CustomCollection<SpecialStringArray> DataList
        {
            get { return _datalist; }
            //set { _rangelist = value; }
        }

        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = false;
            if (entryCommon.Equals("30"))
            {
                return false;
            }

            if (result == null)
            {
                return false;
            }

           

            //也可以按组查询 指定行列为特定值 
            bresult = DataList.Where(t =>! Enum.GetName(typeof(EnumSpecialType), t.SpecialType).Contains("Un"))
                              .Select(t => t.Group).Distinct()
                              .Any(g => DataList.Where(t => t.Group.Equals(g))
                                 //.All(o => CheckSpecificCharacter(result, GetSpeicficResult, CheckspecificResult)));
                              .All(o => CheckSpecificCharacter(result, GetSpeicficResult, o)));

            if (!bresult)
            {
                bresult = DataList.Where(t => Enum.GetName(typeof(EnumSpecialType), t.SpecialType).Contains("Un"))
                              .Select(t => t.Group).Distinct()
                              .Any(g => DataList.Where(t => t.Group.Equals(g))
                              .Any(o => CheckSpecificCharacter(result, GetSpeicficResult, o)));
            }

            if (bresult)
            {
                System.Console.WriteLine("VerfityN0101");
            }

            return bresult;
        }

        private   string GetSpeicficResult(string colResult)
        {
            var splitResult = new Split.SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, colResult);
            return splitResult.GetName();
        }
        //protected bool CheckspecificResult(string result)
        //{

        //    bool bresult = false;

        //    bresult = DataList.Any(t => t.Check(  result));

        //    return bresult;
        //}
        //protected bool CheckspecificResult(int row, int col, string result)
        //{

        //    bool bresult = false;

        //    bresult = DataList.All(t => t.Check(row, col, result));

        //    return bresult;
        //}
    }
}
